#ifndef __Core__
#define __Core__

#include <vector>

#include "iEnvExporter.h"

namespace neiderra { 
	namespace gui
	{
		class iGraphicsSubsystem;
	}
	using gui::iGraphicsSubsystem;
	
	namespace utils
	{
		class Logger;
	}
	using utils::Logger;

	namespace vm 
	{
		class VirtualMachine;
	}
	using vm::VirtualMachine;

	namespace core {

		class iOutputStream;
		class iInputStream;
		class iStream;
		
		class ResourceManager;
		class SceneManager;
		class Module;
		class iLibrary;
		class Environment;
	
		class Core: public iEnvExporter
		{
		public:
			struct eShutDown{};
		
			Core();
			virtual ~Core();
		
			//
			// Streaming
			//
			virtual iOutputStream* createOutputStream();
			virtual iInputStream* createInputStream();
			virtual void deleteStream(iStream*);
			virtual void closeStreams();

			// Creates new library handle
			virtual iLibrary* createLibAdapter() { return 0; }
			
			virtual void setVirtualMachine(VirtualMachine* vm) {_virtualMachine = vm;}
			virtual void setGraphicsSubsystem(iGraphicsSubsystem* ags){ _graphicsSubsystem = ags; }
			virtual void setLogger(Logger* logger){_logger = logger;}
			virtual void setEnvironment(Environment* e) {_environment = e;}
			
			virtual VirtualMachine* getVirtualMachine() {return _virtualMachine;}
			virtual iGraphicsSubsystem* getGraphicsSubsystem() {return _graphicsSubsystem; }
			virtual ResourceManager* getResourceManager() { return _resourceManager; }
//			virtual SceneManager* getSceneManager(){ return _sceneManager; }
			virtual Logger* getLogger() {return _logger;}
			virtual Environment* getEnvironment() {return _environment;}
			
			virtual int run(int argc, char** argv);
			virtual int step(double deltaT);
			virtual bool isWorking() { return !_stop; }

			// 
			// iEnvExporter interface
			//
			virtual void executeMethod(const string& name, const list<string>& args );
			virtual void exportMembers();
			
			void shutdown();
			void powerup();
		
		protected:
			virtual int init();
			
		protected:
			std::vector<iStream*> _streams;
			iOutputStream* _logstream;

			Logger* _logger;
			VirtualMachine*	_virtualMachine;
			iGraphicsSubsystem* _graphicsSubsystem;
			ResourceManager* _resourceManager;
//			SceneManager* _sceneManager;
			Environment* _environment;

			bool _stop;
		};

	}
}

#endif
